package pk.nak.adapters;

import java.util.ArrayList;
import pk.nak.data.EatOut;
import pk.nak.client.R;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class EatOutAdapter extends ArrayAdapter<EatOut> {

	private ArrayList<EatOut> eatouts;
	
	public EatOutAdapter(Context context, int textViewResourceId,ArrayList<EatOut> objects) {
		super(context, textViewResourceId, objects);
		this.eatouts = objects;
	}

	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		View v = convertView;
		if ( v == null ){
			LayoutInflater vi = (LayoutInflater)this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			v = vi.inflate(R.layout.eatoutrow,null);
		}
		
		EatOut eo = this.eatouts.get(position);
		
		if ( eo != null ){
			TextView tvName = (TextView)v.findViewById(R.id.tvEatoutName);
			TextView tvType = (TextView)v.findViewById(R.id.tvEatOutType);
			TextView tvDist = (TextView)v.findViewById(R.id.tvEatOutDistance);
			
			if ( tvName != null ) tvName.setText(eo.getEatoutName());
			if ( tvType != null ) tvType.setText(eo.getEatoutType());
			if ( tvDist != null ) tvDist.setText(""+eo.getEatoutDistance());
		}
		return v;
	}
	
	
}
